/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horizon.gui.component;

import horizon.graphics.RenderingContext;
import horizon.util.Vector2;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

/**
 *
 * @author J_Laptop
 */
public class GuiTextBlock extends GuiComponent {

    ArrayList<String> lines = new ArrayList<>();
    Color bgColor;
    Color textColor;
    Color outlineColor;
    int maxLines = 0;
    int line = 0;

    public GuiTextBlock(String name, Color bgColor, Color textColor, Color outlineColor, Vector2 size, Vector2 position) {
        super(name, size, position);
        this.bgColor = bgColor;
        this.textColor = textColor;
        this.outlineColor = outlineColor;
    }

    public GuiTextBlock(String name, Color bgColor, Color textColor, Vector2 size, Vector2 position) {

        this(name, bgColor, textColor, Color.black, size, position);

    }

    @Override
    public void update(long elapsedTime) {
    }

    @Override
    public void render(RenderingContext r) {
        lines.trimToSize();
        r.drawFilledRectangle(componentBox, bgColor);
        r.drawRectangle(componentBox, outlineColor);

        int lineHeight = r.getGraphics().getFontMetrics().getHeight() - 2;
        maxLines = Math.round(size.getY() / lineHeight);

        if (lines.size() > 0) {

            int n = 0;
            for (int i = 0; i < maxLines; i++) {

                int lineNum = lines.size() - i;

                if (lineNum < lines.size() && lineNum >= 0) {

                    r.drawText(lines.get(lineNum), position.add(new Vector2(0, size.getY())).sub(new Vector2(0, n * lineHeight + 3)), textColor);
                    n++;
                }

            }

        }
    }

    public void addLine(String l) {

        lines.add(l);


    }

    @Override
    public void onActivate(MouseEvent e) {
        
    }
}
